﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;

namespace PRE
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        DAL.Entities_DAL.TaikhoanDAL _dal = new DAL.Entities_DAL.TaikhoanDAL();
        BLL.Entities_BLL.TaikhoanBLL _bll = new BLL.Entities_BLL.TaikhoanBLL();

        private const string STR_LOGIN = "Đăng &nhập";
        private const string STR_LOGOUT = "Đăng &xuất";

        public static UTL.Session _sss = new UTL.Session();

        public frmMain()
        {
            InitializeComponent();
        }

        private void bbiDichvu_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void bbiDangnhap_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (bbiDangnhap.Caption == STR_LOGOUT)
            {
                _sss.Login = false;
                bbiDangnhap.Caption = STR_LOGIN;
            }

            var x = new Catalog.frmLogin();
            x.ShowDialog();

            if (_sss.Login)
            {
                bsiUser.Caption = _sss.Name;
                txtTen.Text = _sss.Name;
                role.Text = _sss.Role + "";
                
                //lbTDN.Text = "Tên truy cập: " + _sss.Acc + "";
               // _User = _sss.Acc;
                bbiDangnhap.Caption = STR_LOGOUT;

                rpTC.Visible = true;
                rpgND.Visible = true;
                rpTKe.Visible = true;
                rpQLDM.Visible = true;
            }
            else
            {                
                bsiUser.Caption = _sss.Name;
                txtTen.Text = _sss.Name;
                role.Text = "None";
                rpgND.Visible = false;
                rpTKe.Visible = false;
                rpQLDM.Visible = false;
                rpgND.Visible = false;
                bbiPhanquyen.Visibility = BarItemVisibility.Never;
                bbiTaikhoan.Visibility = BarItemVisibility.Never;
                bbiDMK.Visibility = BarItemVisibility.Never;
            }

            EnableMenu();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            bbiDangnhap_ItemClick(sender, null);
        }
        //phan quyen
        private void EnableMenu()
        {
            switch (_sss.Role)
            {
                case UTL.Session.Roles.Administrator:
                    rpQLDM.Visible = true;
                    rpgND.Visible = true;
                    rpTKe.Visible = true;
                    bbiPhanquyen.Visibility = BarItemVisibility.Always;
                    bbiTaikhoan.Visibility = BarItemVisibility.Always;
                    bbiDMK.Visibility = BarItemVisibility.Always;

                    break;

                case UTL.Session.Roles.Manager:
                    rpgND.Visible = true;
                    rpTKe.Visible = true;
                    rpgND.Visible = false;
                    bbiPhanquyen.Visibility = BarItemVisibility.Never;
                    bbiTaikhoan.Visibility = BarItemVisibility.Never;
                    break;

                case UTL.Session.Roles.Staff:
                    rpQLDM.Visible = true;
                    rpgND.Visible = true;
                    rpTKe.Visible = true;
                    rpgHoadon.Visible = true;
                    rpgND.Visible = false;
                    bbiPhanquyen.Visibility = BarItemVisibility.Never;
                    bbiTaikhoan.Visibility = BarItemVisibility.Never;
                    bbiNhanvien.Visibility = BarItemVisibility.Never;
                    bbiBGN.Visibility = BarItemVisibility.Never;
               
                    break;

                case UTL.Session.Roles.User:
                    rpQLDM.Visible = true;
                    rpgND.Visible = false;
                    rpTKe.Visible = false;
                    rpgHoadon.Visible = false;
                    bbiPhanquyen.Visibility = BarItemVisibility.Never;
                    bbiTaikhoan.Visibility = BarItemVisibility.Never;
                    bbiNhanvien.Visibility = BarItemVisibility.Never;
                    bbiBGN.Visibility = BarItemVisibility.Never;
                    bbiDichvu.Visibility = BarItemVisibility.Never;
                    
                    break;

                default:
                    break;
            }
        }

        private void toolTip1_Popup(object sender, PopupEventArgs e)
        {

        }

        private void bbiTaikhoan_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.frmTaikhoan) return;
            var frm = new Catalog.frmTaikhoan() { MdiParent = this };
            frm.Show();
        }

        private void bbiKhachhang_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.frmKhachhang) return;
            var frm = new Catalog.frmKhachhang() { MdiParent = this };
            frm.Show();
        }

        private void bbiNhanvien_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.frmNhanvien) return;
            var frm = new Catalog.frmNhanvien() { MdiParent = this };
            frm.Show();
        }

        private void bbiLHD_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.frmLoaiHD) return;
            var frm = new Catalog.frmLoaiHD() { MdiParent = this };
            frm.Show();
        }

        private void bbiNV_CC_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.frmNV_CC) return;
            var frm = new Catalog.frmNV_CC() { MdiParent = this };
            frm.Show();
        }

        private void bbiCanho_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.frmCanho) return;
            var frm = new Catalog.frmCanho() { MdiParent = this };
            frm.Show();
        }

        private void bbiChunhcu_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.frmChungcu) return;
            var frm = new Catalog.frmChungcu() { MdiParent = this };
            frm.Show();
        }
    }
}